package controller;

import service.GoodsService;
import service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delete")
public class GoodsDelete extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String gids= req.getParameter("gid");
        System.out.println(gids);
        int gid= Integer.parseInt(gids);


        GoodsService service = new GoodsServiceImpl();
        int i = service.deleteGoods(gid);
        if (i != 0) {
            req.setAttribute("de", "删除成功");
            resp.sendRedirect("showAll");
        } else {
            req.setAttribute("de", "删除失败");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}

